package org.msfj.admin.data.controller;

import org.msfj.admin.model.FormField;
import org.msfj.admin.vo.FormFieldVo;
import org.msfj.admin.model.FormField;
import org.msfj.admin.vo.FormFieldVo;
import org.msfj.admin.data.service.FormFieldService;
import org.msfj.admin.model.FormField;
import org.msfj.admin.vo.FormFieldVo;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author yangyan
 */
@Api(value = "自定义表单域接口", tags = "自定义表单域接口")
@RestController
@RequestMapping("data/formField")
public class FormFieldController extends BaseController {

    @Autowired
    private FormFieldService formFieldService;

    /**
     * 添加自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok(FormFieldVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加自定义表单域", notes = "添加自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult addFormField(FormFieldVo formFieldVo) {
        FormField formField = formFieldService.saveOrEdit(formFieldVo);
        return CommonResult.ok(formFieldService.setOtherProperties(formField));
    }

    /**
     * 修改自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok(FormFieldVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改自定义表单域", notes = "修改自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult editFormField(FormFieldVo formFieldVo) {
        FormField formField = formFieldService.saveOrEdit(formFieldVo);
        return CommonResult.ok(formFieldService.setOtherProperties(formField));
    }

    /**
     * 逻辑删除自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok(FormFieldVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除自定义表单域", notes = "逻辑删除自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult delFormField(FormFieldVo formFieldVo) {
        FormField formField = formFieldService.delById(formFieldVo);
        return CommonResult.ok(formFieldService.setOtherProperties(formField));
    }

    /**
     * 逻辑删除系统用户信息
     *
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除自定义表单域", notes = "逻辑删除自定义表单域")
    @ApiImplicitParam(value = "ids[]", name = "ids[]", dataType = "java.util.List", paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]", required = false) List<String> ids) {
        FormField formField = new FormField();
        formFieldService.delByIds(ids, formField);
        return CommonResult.ok();
    }

    /**
     * 真实删除自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除自定义表单域", notes = "真实删除自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult deleteFormField(FormFieldVo formFieldVo) {
        formFieldService.trueDelById(formFieldVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok(FormFieldVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找自定义表单域", notes = "根据id查找自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult getFormField(FormFieldVo formFieldVo) {
        FormField formField = formFieldService.getById(formFieldVo.getId());
        return CommonResult.ok(formFieldService.setOtherProperties(formField));
    }

    /**
     * 根据翻页参数、搜索参数查找自定义表单域
     *
     * @param formFieldVo
     * @param page        当前第几页
     * @param rows        每页多少条记录
     * @return CommonResult.ok(PageInfo < FormFieldVo >)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找自定义表单域", notes = "根据翻页参数、搜索参数查找自定义表单域")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "page", dataType = "Integer", paramType = "path"),
            @ApiImplicitParam(name = "rows", value = "rows", dataType = "Integer", paramType = "path")
    })
    public CommonResult findFormFieldList(FormFieldVo formFieldVo, Integer page, Integer rows) {
        PageInfo<FormFieldVo> formFieldVoPageInfo = formFieldService.getByFormField(formFieldVo, page, rows);
        return CommonResult.ok(formFieldVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有自定义表单域
     *
     * @param formFieldVo
     * @return CommonResult.ok(List < FormFieldVo >)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有自定义表单域", notes = "根据搜索参数查找所有自定义表单域")
    @ApiImplicitParam(value = "formFieldVo", name = "formFieldVo", dataType = "org.msfj.admin.vo.FormFieldVo", paramType = "query")
    public CommonResult getAllFormField(FormFieldVo formFieldVo) {
        List<FormFieldVo> formFieldVoList = formFieldService.getAllFormField(formFieldVo);
        return CommonResult.ok(formFieldVoList);
    }
}
